package mysql

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"leaf/db/yorick"
	"leaf/log"
	"time"
)

func Run_mysql(addr string) {
	db, err := sql.Open("mysql", addr)
	if err != nil {
		fmt.Println(err)
	}

	db.SetConnMaxLifetime(time.Minute * 3)
	db.SetMaxOpenConns(10)
	db.SetMaxIdleConns(10)

	defer db.Close()

	err = db.Ping()
	if err != nil {
		panic(err.Error())
	}
	yorick.System.MySqlClient = db
	log.Success("开启数据库成功 %s", addr)
}
